package com.xxpt.model;

import lombok.Data;

@Data
public class Result<T> {
    private String message;
    private String code;
    private T data;

    public Result() {
        this.code = "200";
    }

    public static <T> Result ok(T data, String msg) {
        Result response = new Result();
        response.setCode("200");
        response.setData(data);
        response.setMessage(msg);
        return response;
    }

    public static <T> Result ok(T data) {
        return Result.ok(data, "OK");
    }

    public static Result ok() {
        return Result.ok(null);
    }

    public static Result error() {
        return Result.error("未知异常");
    }

    public static Result error(String message) {
        return Result.error("500", "未知错误");
    }

    /*public static FeignResponse error(ErrorCode errorCode) {
        return FeignResponse.error(errorCode.getCode(), errorCode.getDesc());
    }*/

    public static Result error(String code, String msg) {
        Result result = new Result();
        result.setMessage(msg);
        result.setCode(code);
        result.setData(null);
        return result;
    }
}